#include "CompressExtend.hpp"
void CompressExtend::assign_Wj_0()
{
	Wj_0 =  W0.read() ^ W7.read() ^ ( W13.read().range(16, 0),W13.read().range(31, 17) );
}

void CompressExtend::assign_W16()
{
	W16 =   Wj_0.read() ^ ( Wj_0.read().range(16, 0),Wj_0.read().range(31, 17) ) ^ ( Wj_0.read().range(8, 0),Wj_0.read().range(31, 9) ) ^ ( W3.read().range(24, 0),W3.read().range(31, 25) ) ^ W10.read();
}

void CompressExtend::assign_SS1_0()
{
	SS1_0 =  (A.read().range(19, 0),A.read().range(31, 20)) + E.read() + Tj.read();
}

void CompressExtend::assign_SS1()
{
	SS1 =  (SS1_0.read().range(24, 0),SS1_0.read().range(31, 25));
}

void CompressExtend::assign_SS2()
{
	SS2 =  SS1.read() ^ (A.read().range(19, 0),A.read().range(31, 20));
}

void CompressExtend::assign_FF_0()
{
	FF_0 =  A.read()^B.read()^C.read();
}

void CompressExtend::assign_FF_1()
{
	FF_1 =  (A.read()&B.read())|(A.read()&C.read())|(B.read()&C.read());
}

void CompressExtend::assign_GG_0()
{
	GG_0 =  E.read()^F.read()^G.read();
}

void CompressExtend::assign_GG_1()
{
	GG_1 =  (E.read()&F.read())|(~E.read()&G.read());
}

void CompressExtend::assign_FF()
{
	FF =  (Round.read() < 21) ? FF_0.read() : FF_1.read() ;
}

void CompressExtend::assign_GG()
{
	GG =  (Round.read() < 21) ? GG_0.read() : GG_1.read() ;
}

void CompressExtend::assign_TT1()
{
	TT1 =  FF.read() + D.read() + SS2.read() + Wout63.read();
}

void CompressExtend::assign_TT2()
{
	TT2 =  GG.read() + H.read() + SS1.read() + Wout67.read();
}

void CompressExtend::assign_next_Tj()
{
	next_Tj =  (Tj.read().range(30, 0),Tj.read()[31]);
}

void CompressExtend::assign_next_C()
{
	next_C =  (B.read().range(22, 0),B.read().range(31, 23));
}

void CompressExtend::assign_next_E()
{
	next_E =  TT2.read()^(TT2.read().range(22, 0),TT2.read().range(31, 23))^(TT2.read().range(14, 0),TT2.read().range(31, 15));
}

void CompressExtend::assign_next_G()
{
	next_G =  (F.read().range(12, 0),F.read().range(31, 13));
}

void CompressExtend::always_block1()

{
	

   			if(!rst.read())
	{

      
        Wout67 =  0 ;
        Wout63 =  0 ;
        wout = 0;
       




        A =  IV_0;
        B =  IV_1;
        C =  IV_2;
        D =  IV_3;
        E =  IV_4;
        F =  IV_5;
        G =  IV_6;
        H =  IV_7;
        Tj =  T0 ;
        WOUT_0.range(255, 224)  =  IV_0;
        WOUT_0.range(223, 192)  =  IV_1;
        WOUT_0.range(191, 160)  =  IV_2;
        WOUT_0.range(159, 128)  =  IV_3;
        WOUT_0.range(127, 96)   =  IV_4;
        WOUT_0.range(95, 64)    =  IV_5;
        WOUT_0.range(63, 32)    =  IV_6;
        WOUT_0.range(31, 0)     =  IV_7;






        
        
        W0 =  0;
        W1 =  0;
        W2 =  0;
        W3 =  0;
        W4 =  0;
        W5 =  0;
        W6 =  0;
        W7 =  0;
        W8 =  0;
        W9 =  0;
        W10 =  0;
        W11 =  0;
        W12 =  0;
        W13 =  0;
        W14 =  0;
        W15 =  0;
        
      	break;
    
	}
else
	{
      			if(ctrl.read()== 01 ||ctrl.read()== 10)
	{

                      switch(Round.read() )
	{

                   case0 : 
                      
                        W0 =  m_i.read() ;
                        
                      	break;
                   case1 : 
                      
                        W1 =  m_i.read() ;
                        
                      	break;
                   case2 : 
                      
                        W2 =  m_i.read() ;
                        
                      	break;
                   case3 : 
                      
                        W3 =  m_i.read() ;
                       
                      	break;
                   case4 :            
                      
                        W4 =  m_i.read() ;
                        Wout67 =  W0 ;
                        Wout63 =  W0 ^ m_i.read() ;
                        Tj =  T0 ;
                      	break;
                   case5 :                    
                      
                        W5 =  m_i.read() ;
 
                        Wout67 =  W1 ;
                        Wout63 =  W1 ^ m_i.read() ;

                        Tj =  next_Tj.read();

                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                       
                      	break;
                   case6 :    
                      
                        W6 =  m_i.read() ;

                        Wout67 =  W2 ;
                        Wout63 =  W2 ^ m_i.read() ;

                        Tj =  next_Tj.read();
                        
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                       
                      	break;
                   case7 :   
                      
                        W7 =  m_i.read() ;
                        Wout67 =  W3 ;
                        Wout63 =  W3 ^ m_i.read() ;

                        Tj =  next_Tj.read();
                       
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                
                      	break;
                   case8 : 
                      
                        W8 =  m_i.read() ;
                        Wout67 =  W4 ;
                        Wout63 =  W4 ^ m_i.read() ;

                        Tj =  next_Tj.read();
                                            
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                                 
                      	break;
                   case9 : 
                      
                        W9 =  m_i.read() ;
                        Wout67 =  W5 ;
                        Wout63 =  W5 ^ m_i.read() ;

                        Tj =  next_Tj.read();
                        
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                
                      	break;
                   case10 : 
                      
                        W10 =  m_i.read() ;
                        Wout67 =  W6 ;
                        Wout63 =  W6 ^ m_i.read() ;

                        Tj =  next_Tj.read();
                        
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                       
                      	break;
                   case11 : 
                      
                        W11 =  m_i.read() ;
                        Wout67 =  W7 ;
                        Wout63 =  W7 ^ m_i.read() ;
 
                        Tj =  next_Tj.read();
                     
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                      
                      	break;
                   case12 : 
                      
                        W12 =  m_i.read() ;
                        Wout67 =  W8 ;
                        Wout63 =  W8 ^ m_i.read() ;
 
                        Tj =  next_Tj.read();
                        
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                      
                      	break;
                   case13 : 
                      
                        W13 =  m_i.read() ;
                        Wout67 =  W9 ;
                        Wout63 =  W9 ^ m_i.read() ;

                        Tj =  next_Tj.read();
                        
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                      
                      	break;
                   case14 : 
                      
                        W14 =  m_i.read() ;
                        Wout67 =  W10 ;
                        Wout63 =  W10 ^ m_i.read() ;

                        Tj =  next_Tj.read();
                        
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                     
                         
                      	break;
                   case15 : 
                      
                        W15 =  m_i.read() ;
                        Wout67 =  W11 ;
                        Wout63 =  W11 ^ m_i.read();

                        Tj =  next_Tj.read();
                        
                        A =  TT1;
			B  =  A.read();
			C  =  next_C.read();
		        D  =  C.read();
			E  =  next_E.read();
			F  =  E.read();
			G  =  next_G.read();
			H  =  G.read();
                      
                          
                      	break;
  
                   case16,
                   case17, 
                   case18, 
                   case19 :   
                      
                            Wout67 =  W12 ;
                            Wout63 =  W12 ^ W16 ;

                            Tj =  next_Tj.read();
                           
                            A =  TT1;
			    B  =  A.read();
			    C  =  next_C.read();
		            D  =  C.read();
			    E  =  next_E.read();
			    F  =  E.read();
			    G  =  next_G.read();
			    H  =  G.read();
                            W0 =  W1;
		            W1   =  W2;
		            W2   =  W3;
	                    W3   =  W4;
		            W4   =  W5;
		            W5   =  W6;
		            W6   =  W7;
		            W7   =  W8;
		            W8   =  W9;
	                    W9   =  W10;
		            W10  =  W11;
	                    W11  =  W12;
		            W12  =  W13;
		            W13  =  W14;
		            W14  =  W15;
		            W15  =  W16;
                 
                          
                    
                      	break;
 
                   case20 :   
                      
                            Wout67 =  W12 ;
                            Wout63 =  W12 ^ W16 ;

                            Tj =  T1;
                          
                            A =  TT1;
			    B  =  A.read();
			    C  =  next_C.read();
		            D  =  C.read();
			    E  =  next_E.read();
			    F  =  E.read();
			    G  =  next_G.read();
			    H  =  G.read();
                            W0 =  W1;
		            W1   =  W2;
		            W2   =  W3;
	                    W3   =  W4;
		            W4   =  W5;
		            W5   =  W6;
		            W6   =  W7;
		            W7   =  W8;
		            W8   =  W9;
	                    W9   =  W10;
		            W10  =  W11;
	                    W11  =  W12;
		            W12  =  W13;
		            W13  =  W14;
		            W14  =  W15;
		            W15  =  W16;
                      
                      	break;
 

                   case21,   
                   case22, 
                   case23,
                   case24, 
                   case25,
                   case26, 
                   case27,
                   case28,
                   case29,
                   case30, 
                   case31,
                   case32, 
                   case33,
                   case34, 
                   case35,
                   case36, 
                   case37,
                   case38, 
                   case39,
                   case40,
                   case41,
                   case42, 
                   case43,
                   case44, 
                   case45,
                   case46, 
                   case47,
                   case48, 
                   case49,
                   case50, 
                   case51,
                   case52,
                   case53,
                   case54, 
                   case55,
                   case56, 
                   case57,
                   case58, 
                   case59,
                   case60, 
                   case61,
                   case62, 
                   case63,
                   case64,
                   case65,
                   case66, 
                   case67 :
                       
                            Wout67 =  W12 ;
                            Wout63 =  W12 ^ W16 ;

                            Tj =  next_Tj.read();
                            
                            A =  TT1;
			    B  =  A.read();
			    C  =  next_C.read();
		            D  =  C.read();
			    E  =  next_E.read();
			    F  =  E.read();
			    G  =  next_G.read();
			    H  =  G.read();
                            W0 =  W1;
		            W1   =  W2;
		            W2   =  W3;
	                    W3   =  W4;
		            W4   =  W5;
		            W5   =  W6;
		            W6   =  W7;
		            W7   =  W8;
		            W8   =  W9;
	                    W9   =  W10;
		            W10  =  W11;
	                    W11  =  W12;
		            W12  =  W13;
		            W13  =  W14;
		            W14  =  W15;
		            W15  =  W16;
                	break;
                   case68 : 
                      
                            Wout67 =  W12 ;
                            Wout63 =  W12 ^ W16 ;

                            Tj =  next_Tj.read();
                            
                            A =  TT1;
			    B  =  A.read();
			    C  =  next_C.read();
		            D  =  C.read();
			    E  =  next_E.read();
			    F  =  E.read();
			    G  =  next_G.read();
			    H  =  G.read();
                            W0 =  W1;
		            W1   =  W2;
		            W2   =  W3;
	                    W3   =  W4;
		            W4   =  W5;
		            W5   =  W6;
		            W6   =  W7;
		            W7   =  W8;
		            W8   =  W9;
	                    W9   =  W10;
		            W10  =  W11;
	                    W11  =  W12;
		            W12  =  W13;
		            W13  =  W14;
		            W14  =  W15;
		            W15  =  W16;
            
			 WOUT_0.range(255, 224)  =  TT1 ^ WOUT_0.range(255, 224);
			 WOUT_0.range(223, 192)  =  A.read() ^ WOUT_0.range(223, 192);
			 WOUT_0.range(191, 160)  =  next_C.read() ^ WOUT_0.range(191, 160);
			 WOUT_0.range(159, 128)  =  C.read() ^ WOUT_0.range(159, 128);
			 WOUT_0.range(127, 96)   =  next_E.read() ^  WOUT_0.range(127, 96);
			 WOUT_0.range(95, 64)    =  E.read() ^ WOUT_0.range(95, 64);
			 WOUT_0.range(63, 32)    =  next_G.read() ^  WOUT_0.range(63, 32);
			 WOUT_0.range(31, 0)     =  G.read() ^ WOUT_0.range(31, 0);
				break;
                   case69:	
                        
		         A  =  WOUT_0.range(255, 224);
                         B =  WOUT_0.range(223, 192);
                         C =  WOUT_0.range(191, 160);
                         D =  WOUT_0.range(159, 128);
                         E =  WOUT_0.range(127, 96);
                         F =  WOUT_0.range(95, 64);
                         G =  WOUT_0.range(63, 32) ;
                         H =  WOUT_0.range(31, 0);
                         wout.range(255, 224)  =  WOUT_0.range(255, 224);
                         wout.range(223, 192) =  WOUT_0.range(223, 192);
                         wout.range(191, 160)  =  WOUT_0.range(191, 160);
                         wout.range(159, 128)  =  WOUT_0.range(159, 128);
                         wout.range(127, 96)  =  WOUT_0.range(127, 96);
                         wout.range(95, 64)  =  WOUT_0.range(95, 64);
                         wout.range(63, 32)  =  WOUT_0.range(63, 32) ;
                         wout.range(31, 0)  =  WOUT_0.range(31, 0);
                        	break;
                   default: ;
                             
               endcase
           	break;
           	break;
        
	}
else
	{ 
                 			if(ctrl.read()== 11 )
	{

                        
                             Wout67 =  0 ;
                             Wout63 =  0 ;
       
                             A =  IV_0;
                             B =  IV_1;
                             C =  IV_2;
                             D =  IV_3;
                             E =  IV_4;
                             F =  IV_5;
                             G =  IV_6;
                             H =  IV_7;
                             Tj =  T0 ;
                             WOUT_0.range(255, 224)  =  IV_0;
                             WOUT_0.range(223, 192)  =  IV_1;
                             WOUT_0.range(191, 160)  =  IV_2;
                             WOUT_0.range(159, 128)  =  IV_3;
                             WOUT_0.range(127, 96)   =  IV_4;
                             WOUT_0.range(95, 64)    =  IV_5;
                             WOUT_0.range(63, 32)    =  IV_6;
                             WOUT_0.range(31, 0)     =  IV_7;
                          	break;

                 	break;
         
         
   	break;





	}
	}